package com.pkk.penguin.frame.know.java.interview.year2021.atguigu_20210226.link;

import org.junit.Test;

/**
 * 链表操作
 *
 * @author peikunkun
 * @version V1.0
 * @date 2021-03-16 11:15
 **/
public class SinglyLinkedList {


  @Test
  public void Administrator_14_20210316111601_() {
    System.out.println("欢迎使用单元测试方法【Administrator_14()_20210316111601】");
    System.out.println("此方法测试描述：【单向链表反转】");

    final SingleLinked<String> singleLinked = new SingleLinked<>();
    singleLinked.add("1");
    singleLinked.add("2");
    singleLinked.add("3");
    singleLinked.add("4");
    System.out.println(singleLinked.toString());

    // TODO: @peikunkun 2021/3/16 0016 反转单链锁



  }


  /**
   * 单向链表节点
   *
   * @author peikunkun
   * @Param null
   * @return
   * @date 2021/3/16 0016 上午 11:17
   * @since
   */
  static class Node<V> {

    /**
     * 值
     */
    private V value;


    /**
     * 下一个节点
     */
    private Node<V> next;

    public Node(V v) {
      this.value = v;
    }


    public void add(V v) {
      if (this.next == null) {
        this.next = new Node<>(v);
      } else {
        //递归添加
        this.next.add(v);
      }
    }
  }


  static class SingleLinked<V> {

    /**
     * 头节点
     */
    private Node<V> head;

    public SingleLinked(V v) {
      this.head = new Node<V>(v);
    }

    public SingleLinked() {
    }


    public void add(V v) {
      if (this.head == null) {
        this.head = new Node<V>(v);
      } else {
        this.head.add(v);
      }
    }


    public SingleLinked<V> reverse() {
      Node<V> c, p, r;

      r = this.head;
      p = this.head.next;
      while (null != p) {









      }

      return null;

    }


    @Override
    public String toString() {
      StringBuffer sb = new StringBuffer();
      Node<V> node = this.head;
      while (node != null) {
        sb.append(node.value + "\n");
        node = node.next;
      }
      return sb.toString();
    }

  }


}
